﻿using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NewBee.Core.Data.Model
{
    public class SuccessResult:BaseModel
    {
        IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();

        public SuccessResult()
        {
            timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            this.StartTime = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString();
        }

        public SuccessResult GetSuccessResult(string json)
        {
            return (SuccessResult)Newtonsoft.Json.JsonConvert.DeserializeObject(json, this.GetType());
        }

        public bool Success { get; set; }
        public string Message { get; set; }
        public string ErrCode { get; set; }
        public object Data { get; set; }

        private string _StartTime = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString();
        public string StartTime { get{ return _StartTime; } set { _StartTime = value; } }
        public string EndTime { get; set; }

        public string toString()
        {
            this.EndTime = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString();
            return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented, timeFormat);
        }

        public string toErrMessage(string message)
        {
            this.Success = false;
            this.EndTime = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString();
            this.Message = message;
            return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented, timeFormat);
        }

        public string toSysErrMessage(string message)
        {
            this.Success = false;
            this.EndTime = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString();
            this.Message = message;
            return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented, timeFormat);
        }
    }
}
